package com.zxbg.service.impl.systemtoolsServiceImpl;

import com.zxbg.dao.SettingDao;
import com.zxbg.domain.Internationalization;
import com.zxbg.domain.Setting;
import com.zxbg.service.systemtoolsService.SecurityManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SecurityManagementServiceImpl implements SecurityManagementService {
    @Autowired
    SettingDao settingDao;

    @Override
    public Setting getAllSettingsMap(Integer tenant_id) {
        Setting settingMap = settingDao.getAllSettingsMap(tenant_id);
        settingMap.setBrowser_name(new Internationalization(settingMap.getBrowser_name_zh(), settingMap.getBrowser_name_en()));
        return settingMap;
    }

    @Override
    public boolean setSetting(String type, String value, Integer tenant_id) {
        try {
            Integer newValue = Integer.parseInt(value);
            return settingDao.setIntSetting(type, newValue, tenant_id) > 0;
        } catch (Exception e) {
            return settingDao.setStringSetting(type, value, tenant_id) > 0;
        }
    }

    @Override
    public Integer getLoginCodeByTenantId(Integer tenant_id) {
        return settingDao.getLoginCodeByTenantId(tenant_id);
    }
}
